#include <AT89X52.H>
#include "keypad.h"
#include "typedef.h"
#include "uart.h"
#include "pdiusb.h"

/* uart is 9600 */
void main(void)
{
    u16 tmp = 0;
    u16 array_len = 0;
    u8 interruprSrc = 0;
    u8 i = 0;

    hasSendHIDdesc = 0;

    USART_Configure();
    InitTimer0();

    UsbInit();

    //tmp = D12ReadID();

    UsbDisconnect();
    UsbConnect();
    array_len = sizeof(interruptCase)/sizeof(case_func);
    while(1){
  	if(D12GetIntPin()==0){
		D12WriteCommand(READ_INTERRUPT_REG);
		interruprSrc = D12ReadByte();
		for(i=0; i<array_len; i++){
			if(interruprSrc&interruptCase[i].case_num){
				interruptCase[i].func();
                		break;
			}
		}
	}
	if(1 == hasSendHIDdesc){
		SendReport();
	}
    }

    while(1){
        USART_SendByte(0x95);
    	USART_SendByte(0x27);
    }
}
